package zhtt.example.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by zhaoq on   2024/8/3 16:21
 **/
@RestController
public class RequestHeaderController {

    @Autowired
    private HttpServletRequest httpServletRequest;

    @RequestMapping(value="/header", method= RequestMethod.GET)
    public Map<String, String> header(@RequestHeader(value = "token1", required = false) String token1,
                       @RequestHeader(value = "token0", required = false) String token0) {
        Map<String, String> map = new HashMap<>();
        String tk0 = httpServletRequest.getHeader("token0");
        String tk1 = httpServletRequest.getHeader("token1");
        String referer = httpServletRequest.getHeader("referer");
        String path = httpServletRequest.getServletPath();
        System.out.println(path+"[referer]:"+referer);
        map.put("token1", token1);
        map.put("token0", token0);
        map.put("tk0", tk0);
        map.put("tk1", tk1);
        return map;
    }

    @RequestMapping(value="/header1", method= RequestMethod.GET)
    public Map<String, String> header1(@RequestHeader(value = "token1", required = false) String token1,
                       @RequestHeader(value = "token0", required = false) String token0) {
        return header(token1, token0);
    }

    @RequestMapping(value="/header2", method= RequestMethod.GET)
    public Map<String, String> header2(@RequestHeader(value = "token1", required = false) String token1,
                       @RequestHeader(value = "token0", required = false) String token0) {
        return header(token1, token0);
    }

    @RequestMapping(value="/header3", method= RequestMethod.GET)
    public Map<String, String> header3(@RequestHeader(value = "token1", required = false) String token1,
                       @RequestHeader(value = "token0", required = false) String token0) {
        return header(token1, token0);
    }

    @RequestMapping(value="/header4", method= RequestMethod.GET)
    public Map<String, String> header4(@RequestHeader(value = "token1", required = false) String token1,
                       @RequestHeader(value = "token0", required = false) String token0) {
        return header(token1, token0);
    }

    @RequestMapping(value="/header5", method= RequestMethod.GET)
    public Map<String, String> header5(@RequestHeader(value = "token1", required = false) String token1,
                       @RequestHeader(value = "token0", required = false) String token0) {
        return header(token1, token0);
    }
}
